    $(function () {
        var nowOrderId='';                     //存编辑订单的ID
        var xuanZeDeHuoDongId='';              //存活动id

        var step = 1;
        //执行一个laydate实例
        laydate.render({
            elem: '#startTime' //指定元素
        });

        laydate.render({
            elem: '#endTime'
        });

        $('.user').on('click', function () {
            $(this).toggleClass('hover');
        })

        $('.user').mouseleave(function () {
            $(this).removeClass('hover');
        });


        $('.dropdown').on('click', function () {

            if ($(this).hasClass("open")) {
                $(this).removeClass('open');
            } else {
                $('.dropdown').removeClass('open');
                $(this).addClass('open');
            }
        })

        // 
        $('.wuYuSuan').on('click', function () {
            if ($(this).hasClass("checked")) {
                $(this).removeClass('checked');
                $(this).prev().removeAttr('disabled');
            } else {

                $(this).addClass('checked');
                $(this).prev().attr('disabled', 'disabled');
            }
        })

        $('.wuYuSuan1').on('click', function () {
            if ($(this).hasClass("checked")) {
                $(this).removeClass('checked');
                $('#endTime').removeAttr('disabled');
            } else {

                $(this).addClass('checked');
                $('#endTime').attr('disabled', 'disabled');
            }
        })

        //下一步
        $('#xiaYiBu').on('click', function () {
            let result = next(step);
            if (result) {
                step = ++step;
            }
        })

        //上一步
        $('#shangYiBu').on('click', function () {

            previous(step);

            if (step > 1) {
                step = --step;
            }

        })

        $('#file').change(function(){
            var str=$(this).val();
            var arr=str.split('\\');//注split可以用字符或字符串分割
            var my=arr[arr.length-1];//这就是要取得的图片名称
            $('#show_img_name').text(my);
        })

        $('#file1').change(function(){
            var str=$(this).val();
            var arr=str.split('\\');//注split可以用字符或字符串分割
            var my=arr[arr.length-1];//这就是要取得的图片名称
            $('#show_img_name1').text(my);
        })


        // let newDingDan= sessionStorage.getItem('newDingDan');
        // $('#huoDongMingCheng').text(newDingDan);


        //请求活动下拉列表（查询所有的活动）

        let token=sessionStorage.getItem("token");
        
        $.ajax({
            type:"GET",
            url:url+"/advertiser/adActivity/allAdActivity",  

            //		参数需转为字符串
            // data: JSON.stringify(d),

            //		json跨域
            dataType: 'json',
            //		contentType类型为json
            contentType: "application/json",

            //		请求头加上X-Token 
             beforeSend: function(XMLHttpRequest) {
                //		token 为页面所获取
                
                XMLHttpRequest.setRequestHeader("X-Token", token); 
            },
            useDefaultXhrHeader: false,
            success: function(result) {
                console.log(result)


                let html = '';
                let listData=result.data;
                listData.forEach(item => {
                    html +=`<li class="cl ng-scope"  onclick="clickFuncHuo(this)">
                                <a data-id='${item.id}' href="javascript:;" class="ng-binding">${item.name}</a>
                                
                            </li>`;

                })
                $('#huoDongChildrenBox').append(html);        
            },
            err: function(err) {
                layer.msg("请求失败");
            },
            complete: function() {
                // $(_that).removeAttr("disabled");
            }
        });


        //请求监测下拉数据
        
        $.ajax({
            type:"GET",
            url:url+"/advertiser/adSuperviseInfo/queryAllAdSuperviseInfo",  

            //		参数需转为字符串
            // data: JSON.stringify(d),

            //		json跨域
            dataType: 'json',
            //		contentType类型为json
            contentType: "application/json",

            //		请求头加上X-Token 
             beforeSend: function(XMLHttpRequest) {
                //		token 为页面所获取
                
                XMLHttpRequest.setRequestHeader("X-Token", token); 
            },
            useDefaultXhrHeader: false,
            success: function(result) {
                console.log(result)

                let html = '';
                let listData=result.data;
                listData.forEach(item => {
                    html +=`<li class="cl ng-scope"  onclick="clickFuncJian(this)">
                                <a data-id='${item.id}' href="javascript:;" class="ng-binding">${item.superviseName}</a>
                            </li>`;

                })
                $('#jianCeChildrenBox').append(html);        
            },
            err: function(err) {
                layer.msg("请求失败");
            },
            complete: function() {
                // $(_that).removeAttr("disabled");
            }
        });
    })

    function clickFunc(e) {
        
        $(e).addClass('checked').siblings(".radio").removeClass('checked');

        if ($(e).attr('value') == 'all') {
            $(e).next().next(".form-group").addClass('ng-hide');
        } else {
            $(e).next(".form-group").removeClass('ng-hide');
        }
    }

    function xingBieDingXiang(e) {
        clickFunc(e);
        let str= $(e).children('span').text();
        if(str=='不限'){
            sessionStorage.setItem('xingBieDingXiang','不限');
        }else{
            sessionStorage.setItem('xingBieDingXiang','男');
        }
    }

    function guangGaoWeiLeiXing(e) {
        clickFunc(e);
        let value= $(e).children('span').text();
        console.log(value);
        sessionStorage.setItem('guangGaoWeiLeiXing',value);
      
    }



    function nianLingDingXiang(e) {
        clickFunc(e);

        let str= $(e).children('span').text();
        if(str=='不限'){
            sessionStorage.setItem('nianLingDingXiang','不限');
        }else{
            sessionStorage.setItem('nianLingDingXiang',null);
        }
        
    }

    function sheBeiJiaGe(e) {
        clickFunc(e);
        let str= $(e).children('span').text();
        if(str=='不限'){
            sessionStorage.setItem('sheBeiJiaGe','不限');
        }else{
            sessionStorage.setItem('sheBeiJiaGe',null);
        }
        
    }

    
    function sheBeiPinPai(e) {
        clickFunc(e);
        let str= $(e).children('span').text();
        if(str=='不限'){
            sessionStorage.setItem('sheBeiPinPai','不限');
        }else{
            sessionStorage.setItem('sheBeiPinPai',null);
        }
        
    }

    function sheBeiBanBen(e) {
        clickFunc(e);
        let str= $(e).children('span').text();
        if(str=='不限'){
            sessionStorage.setItem('sheBeiBanBen','不限');
        }else{
            sessionStorage.setItem('sheBeiBanBen',null);
        }  
    }    
    
    function lianWangFangShi(e) {
        clickFunc(e);
        let str= $(e).children('span').text();
        if(str=='不限'){
            sessionStorage.setItem('lianWangFangShi','不限');
        }else{
            sessionStorage.setItem('lianWangFangShi',null);
        }  
    }

    function yunYingShang(e) {
        clickFunc(e);
        let str= $(e).children('span').text();
        if(str=='不限'){
            sessionStorage.setItem('yunYingShang','不限');
        }else{
            sessionStorage.setItem('yunYingShang',null);
        }  
    }

    

    

    
    function shouRuDingXiang(e) {
        clickFunc(e);
        let str= $(e).children('span').text();
        if(str=='不限'){
            sessionStorage.setItem('shouRuDingXiang','不限');
        }else{
            sessionStorage.setItem('shouRuDingXiang',null);
        } 
    }



    function clickFuncSex(e) {
        
        clickFunc(e);
        let sex=$(e).children('span').text();
        sessionStorage.setItem('xingBieDingXiang',sex);
    }




    function clickFunc1(e) {
        if ($(e).hasClass("checked")) {
            $(e).removeClass('checked');
        } else {
            $(e).addClass('checked');
        }
    }


    function shouRuDingXiangRMB(e) {
        clickFunc1(e);
        // console.log($('#shouRuDingXiang_box').children().length);

        let ary=[];
        $.each($('#shouRuDingXiang_box').children(),function(i,n){
  			// alert("Name:"+i+",Value:"+n);
            
            if($(n).hasClass("checked")){
                ary.push($(n).attr('value'));
            }
            
            // if ($(e).hasClass("checked")) {
            //     $(e).removeClass('checked');
            // } else {
            //     $(e).addClass('checked');
            // }
		});
        sessionStorage.setItem('shouRuDingXiang',JSON.stringify(ary));
    }

    
    function nianLingDingXiangChildren(e) {
        clickFunc1(e);
        let ary=[];

        $.each($('#nianLingDingXiang_box').children(),function(i,n){
  			// alert("Name:"+i+",Value:"+n);
            
            if($(n).hasClass("checked")){
                ary.push($(n).attr('value'));
            }
            
            // if ($(e).hasClass("checked")) {
            //     $(e).removeClass('checked');
            // } else {
            //     $(e).addClass('checked');
            // }
		});
        sessionStorage.setItem('nianLingDingXiang',JSON.stringify(ary));
    }

    function sheBeiJiaGeChildren(e) {
        clickFunc1(e);
        let ary=[];

        $.each($('#sheBeiJiaGe_box').children(),function(i,n){
  			// alert("Name:"+i+",Value:"+n);
            
            if($(n).hasClass("checked")){
                ary.push($(n).attr('value'));
            }
            
            // if ($(e).hasClass("checked")) {
            //     $(e).removeClass('checked');
            // } else {
            //     $(e).addClass('checked');
            // }
		});
        sessionStorage.setItem('sheBeiJiaGe',JSON.stringify(ary));
    }

    function sheBeiBanBenChildren(e) {
        clickFunc1(e);
        let ary=[];

        $.each($('#sheBeiBanBen_box').children(),function(i,n){
  			// alert("Name:"+i+",Value:"+n);
            
            if($(n).hasClass("checked")){
                ary.push($(n).attr('value'));
            }
            
            // if ($(e).hasClass("checked")) {
            //     $(e).removeClass('checked');
            // } else {
            //     $(e).addClass('checked');
            // }
		});
        sessionStorage.setItem('sheBeiBanBen',JSON.stringify(ary));
    }

    function  yunYingShangChildren(e) {
        clickFunc1(e);
        let ary=[];

        $.each($('#yunYingShang_box').children(),function(i,n){
  			// alert("Name:"+i+",Value:"+n);
            
            if($(n).hasClass("checked")){
                ary.push($(n).attr('value'));
            }
            
            // if ($(e).hasClass("checked")) {
            //     $(e).removeClass('checked');
            // } else {
            //     $(e).addClass('checked');
            // }
		});
        sessionStorage.setItem('yunYingShang',JSON.stringify(ary));
    }

    function lianWangFangShiChildren(e) {
        clickFunc1(e);
        let ary=[];

        $.each($('#lianWangFangShi_box').children(),function(i,n){
  			// alert("Name:"+i+",Value:"+n);
            
            if($(n).hasClass("checked")){
                ary.push($(n).attr('value'));
            }
            
            // if ($(e).hasClass("checked")) {
            //     $(e).removeClass('checked');
            // } else {
            //     $(e).addClass('checked');
            // }
		});
        sessionStorage.setItem('lianWangFangShi',JSON.stringify(ary));
    }

    

    function sheBeiPinPaiChildren(e) {
        clickFunc1(e);
        let ary=[];

        $.each($('#sheBeiPinPai_box').children(),function(i,n){
  			// alert("Name:"+i+",Value:"+n);
            
            if($(n).hasClass("checked")){
                ary.push($(n).attr('value'));
            }
            
            // if ($(e).hasClass("checked")) {
            //     $(e).removeClass('checked');
            // } else {
            //     $(e).addClass('checked');
            // }
		});
        sessionStorage.setItem('sheBeiPinPai',JSON.stringify(ary));
    }


    function clickFunc2(e) {
        $(e).addClass('checked').siblings(".radio").removeClass('checked');
        if($(e).attr('value')=='true'){
            $('#liRunZhi').removeAttr('disabled');
        }else if($(e).attr('value')=='false'){
            
            $('#liRunZhi').val('');
            $('#liRunZhi').attr('disabled','disabled');
            
        }


    //     if ($(e).hasClass("checked")) {
    //         $(e).removeClass('checked');
    //     } else {
    //         $(e).addClass('checked');
    //     }
    }

    function clickFunc3(e) {

        $(e).addClass('checked').siblings(".radio").removeClass('checked');

        let touFangSuLv=$(e).attr('value');
        console.log(touFangSuLv);

        if(touFangSuLv=='按花费控制'){
            $('#show_huaFei_ele').removeClass('hide');
            $('#show_zhanShiLiang_ele').addClass('hide');

            
            // let touFangSuLv='按花费控制:';
            // touFangSuLv+=$('#tian').text();
            // touFangSuLv+=$('#yuan').val();
            // touFangSuLv+=$('#tian1').text();
            // localStorage.setItem('touFangSuLv',touFangSuLv);
        }else if(touFangSuLv=='按展示量控制'){
            $('#show_huaFei_ele').addClass('hide');
            $('#show_zhanShiLiang_ele').removeClass('hide');
            // let touFangSuLv='按展示量控制:';
            // touFangSuLv+=$('#qianCi').text();
            // touFangSuLv+=$('#tian3').text();
            // localStorage.setItem('touFangSuLv',touFangSuLv);
        }
        localStorage.setItem('touFangSuLv',touFangSuLv);

    }

    function clickFunc4(e) {

        $(e).addClass('checked').siblings(".radio").removeClass('checked');

        if($(e).attr('value')=='0'){

            $('#show_huaFei_ele').removeClass('hide');
            $('#show_zhanShiLiang_ele').addClass('hide');

        }else if($(e).attr('value')=='1'){
            $('#show_huaFei_ele').addClass('hide');
            $('#show_zhanShiLiang_ele').removeClass('hide');
                
        }
        let houXuXingWei=$(e).attr('value');
        localStorage.setItem('houXuXingWei',houXuXingWei);

    }

    function clickFunc5(e) {

        $(e).addClass('checked').siblings(".radio").removeClass('checked');

        if($(e).attr('value')=='0'){

            $('#show_huaFei_ele').removeClass('hide');
            $('#show_zhanShiLiang_ele').addClass('hide');

        }else if($(e).attr('value')=='1'){
            $('#show_huaFei_ele').addClass('hide');
            $('#show_zhanShiLiang_ele').removeClass('hide');
                
        }
        let caoZuoXiTong=$(e).attr('value');
        localStorage.setItem('caoZuoXiTong',caoZuoXiTong);

    }





    //取消
    function cancel() {
        window.location.href = "./order.html";
    }

    //下一步
    function next(step) {
        let result = inputCheck(step);
        return result;
    }

    function stepJump(step) {
        inputCheck(step);
    }



    //订单填写验证
    function inputCheck(step) {
        if (step == 1) {
            // if (data.activityID == "" || data.activityID == "0") {
            //     error = "请选择活动。";
            //     return error;
            // }

           

            let huoDongContent= $('#huoDongContent').text()
            if(huoDongContent=='请选择活动名称'){
                layer.msg('请选择活动名称！');
                return false;
            }

            let dingDanMingCheng = $('#dingDanMingCheng').val();
            if (dingDanMingCheng == '') {
                layer.msg('请输入订单名称。');
                return false;
            }

            if (!$('.wuYuSuan').hasClass("checked")) {
                let yuSuanKongZhi = $('#yuSuanKongZhi').val();
                if (yuSuanKongZhi == '') {
                    layer.msg('请输入预算控制。');
                    return false;
                } else if (isNaN(yuSuanKongZhi) || yuSuanKongZhi == "0") {
                    layer.msg('预算为大于0的数字！');
                    return false;
                }   
            }   

            // if(!isNaN(t)){

            // alert("是数字");

            // }else{

            // alert("不全是数字");

            // }

            

                

                //保存用户输入的值
                let dingDanData=new Object();
                dingDanData.huoDongMingCheng=$('#huoDongContent').text().trim();

                dingDanData.id=$('#huoDongContent').text().trim();

                dingDanData.dingDanMingCheng=$('#dingDanMingCheng').val();
                dingDanData.shouMaiLeiXing='CPM';
                dingDanData.houXuXingWei=localStorage.getItem('houXuXingWei');
                dingDanData.caoZuoXiTong=localStorage.getItem('caoZuoXiTong');
                dingDanData.yuSuanKongZhi=$('#yuSuanKongZhi').val();

                let touFangSuLv=localStorage.getItem('touFangSuLv');
            // console.log(touFangSuLv);
                if(touFangSuLv=='按花费控制'||touFangSuLv==null){
                
                    // if(!isNaN($('#yuan').val().trim()) ){
                    //     layer.msg('投放速率请填写整数字');
                    //     $('#yuan').focus();
                    //      return false;
                        
                    // }

                    let touFangSuLv='按花费控制:';


                    touFangSuLv+=$('#tian').children('span').text();
                    touFangSuLv+=$('#yuan').val().trim();
                    touFangSuLv+=$('#tian1').text().trim();

                    console.log(touFangSuLv);
                    localStorage.setItem('touFangSuLv',touFangSuLv);
                }else if(touFangSuLv=='按展示量控制'){
                    // console.log($('#qianCi').val().trim());
                    // if(!isNaN($('#qianCi').val().trim())  ){
                    //     layer.msg('投放速率请填写整数字');
                    //     $('#qianCi').focus();
                    //      return false;
                    // }
     
                    let touFangSuLv='按展示量控制:';
                    touFangSuLv+=$('#qianCi').val().trim();

                    touFangSuLv+=$('#tian3').text().trim();
                    console.log(touFangSuLv);
                    localStorage.setItem('touFangSuLv',touFangSuLv.trim());
                }
                
                dingDanData.touFangSuLv=localStorage.getItem('touFangSuLv');
                let ci=$('#ci').val();
                let tian2=$('#tian2').text().trim();
                dingDanData.pinCiZhanShi=ci+'次/'+tian2;

                

                if ($('.wuYuSuan1').hasClass("checked")) {
                    dingDanData.touFangShiJian='长期投放';
                } else {
                    //拼时间

                    let startTime=$('#startTime').val();
                    let endTime=$('#endTime').val();
                    dingDanData.touFangShiJian=startTime+'~'+endTime;
                    
                }
                // 少值还差监测站点。需补站点接口。后面再问
                console.log(dingDanData);
                localStorage.setItem('dingDanData',JSON.stringify(dingDanData));
                // obj=JSON.parse(localStorage.getItem("temp2"));


                //第一项到第二项动态
                $('#dingXiangSheZhi').addClass('cur-step');
                $('#two').addClass('show').removeClass('hide');
                $('#one').addClass('hide').removeClass('show');
                $('#shangYiBu').addClass('show').removeClass('hide');
                $('#quXiao1').addClass('hide').removeClass('show');

                return true;
        } else if (step == 2) {
            $('#xiaYiBu').text('下一步');
            $('#shangChuanSuCai').addClass('cur-step');
            $('#three').addClass('show').removeClass('hide');
            $('#two').removeClass('show').addClass('hide');
            $('#one').addClass('hide').removeClass('show');

            $('#four').addClass('hide').removeClass('show');
            $('#tiJiaoXinXi').removeClass('cur-step');
           
            return true;
            // 

            var ip = scope.data.direct.ip || "",
                ips = ip.split(",");
            if (ip != "") {
                if (ip.indexOf("，") != -1) {
                    error = "ip定向格式错误！多个ip请使用英文的','！";
                    return error;
                }
                for (var i = 0; i < ips.length; i++) {
                    if (!ips[i].match(
                            /(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))/
                        )) {
                        return "ip格式有误";
                    }
                }
            }
            if (scope.bidActive == 2) {
                if (scope.depotCheck.length > 5) {
                    error = "人群库不能超过5个！";
                    return error;
                }
                if (scope.depotCheck.length == 0) {
                    error = "请选择人群库！";
                    return error;
                }
            } else {
                if (scope.position.age == "custom" && scope.position.ages.length == 0) {
                    error = "请选择年龄定向。";
                    return error;
                }
                if (scope.position.income == "custom" && scope.position.incomes.length == 0) {
                    error = "请选择收入定向。";
                    return error;
                }
            }
            if (scope.position.area != "all" && $("#areaCustom .selected-item").length == 0) {
                error = "请选择投放区域。";
                return error;
            }
            if (scope.position.publish == "all" && scope.publishConfig.selectArr.length == 0) {
                error = "必须选择一个流量来源（全网智能优化）。";
                return error;
            }
            if (scope.position.publish == "space" && scope.position.spaceIds.length == 0) {
                error = "请输入指定广告位。";
                return error;
            }
            if (scope.position.publish == 'industry' && !scope.industryPkgId) {
                error = "请选择行业包。";
                return error;
            }
            if (scope.position.publish == 'crowd' && !scope.crowdPkgId) {
                error = "请选择人群包。";
                return error;
            }
            var medias = scope.mediaConfig.selectArr,
                fLen = 0;
            for (var i = 0; i < medias.length; i++) {
                if (medias[i] != "") {
                    fLen++;
                }
            }
            if (scope.position.publish == "select" && fLen == 0) {
                error = "请选择精选媒体。";
                return error;
            }
            medias = scope.newMediaConfig.selectArr
            fLen = 0;
            for (var i = 0; i < medias.length; i++) {
                if (medias[i] != "") {
                    fLen++;
                }
            }
            if (scope.position.publish == "new" && fLen == 0) {
                error = "请选择新品媒体。";
                return error;
            }
            if (scope.position.publish == "type" && $("#typeCustom .selected-item").length == 0) {
                error = "请选择媒体分类。";
                return error;
            }
            if (scope.position.dePrice != "all" && scope.position.dePrices.length == 0) {
                error = "请选择设备价格。";
                return error;
            }
            if (scope.position.deBrand != "all" && scope.position.brandIds.length == 0) {
                error = "请选择设备品牌。";
                return error;
            }
            if (scope.position.deVersion != "all" && scope.position.versionIds.length == 0) {
                error = "请选择系统版本。";
                return error;
            }
            if (scope.position.net != "all" && scope.position.nets.length == 0) {
                error = "请选择联网方式。";
                return error;
            }
            if (scope.position.ISP != "all" && scope.position.ISPs.length == 0) {
                error = "请选择运营商。";
                return error;
            }

        } else if (step == 2 && scope.orderType == 'deal') {
            if (scope.data.SKU.length == 0) {
                error = "请选择一个合约资源。";
                return error;
            }
            alert(111);
        } else if (step == 3) {
            var Obj1 = $("#file")[0].files; 
            console.log(Obj1);
            if(Obj1.length<1){
                layer.msg('请上传素材');
                return false;
                
            }
            $('#tiJiaoXinXi').addClass('cur-step');
            $('#four').addClass('show').removeClass('hide');
            $('#three').removeClass('show').addClass('hide');
            $('#xiaYiBu').text('完成');  
        
            //取值显示在第四个待完成
            // let huoDongMingCheng= sessionStorage.getItem('newDingDan');
            
            // localStorage.setItem('dingDanData',JSON.stringify(dingDanData));

            let dingDanData=JSON.parse(localStorage.getItem("dingDanData"));
            console.log(dingDanData);





            $('#showHuoDongMingCheng').text(dingDanData.huoDongMingCheng);
            $('#showDingDanMingCheng').text(dingDanData.dingDanMingCheng);

            $('#showChuangYiXingShi').text($('#showItem').text());
 


            if(dingDanData.yuSuanKongZhi){
                $('#showYuSuanKongZhi').text(dingDanData.yuSuanKongZhi);
            }

            if(dingDanData.touFangSuLv){
                $('#showTouFangSuLv').text(dingDanData.touFangSuLv);
            }

            if(dingDanData.pinCiZhanShi){
                $('#showPinCiKongZhi').text(dingDanData.pinCiZhanShi);
            }
// 
            if(dingDanData.pinCiZhanShi){
                $('#showPinCiKongZhi').text(dingDanData.pinCiZhanShi);
            }

            $('#showTouFangShiJian').text(dingDanData.touFangShiJian);

           
            if(sessionStorage.getItem('xingBieDingXiang')){
                $('#showXingBieDingXiang').text(sessionStorage.getItem('xingBieDingXiang'));
            }

            if(sessionStorage.getItem('shouRuDingXiang')){
                $('#showShouRuDingXiang').text(sessionStorage.getItem('shouRuDingXiang'));
            }

            if(sessionStorage.getItem('nianLingDingXiang')){
                $('#showNianLingDingXiang').text(sessionStorage.getItem('nianLingDingXiang'));
            }

            if(dingDanData.caoZuoXiTong){
                $('#showCaoZuoXiTong').text(dingDanData.caoZuoXiTong);
            }


            return true;
        } else if (step == 4) {
            let dingDanChuJia=$('#dingDanChuJia').val().trim();


            if (dingDanChuJia == "") {
                layer.msg('请输入订单出价。');
                return false;
            }
            if (dingDanChuJia <= 0) {
                layer.msg('订单出价必须大于0。');
                return false;
            }
            
            // 请求发送订单信息待完成

            let liRunZhi =$('#liRunZhi').val();

           

            //节点未获取到未成功先放着
            // checkRate('liRunZhi');

            
            if (liRunZhi > 100) {

                layer.msg('利润设置不能大于100。');
                return false;
                
            }
            addAdorder();
        }
    }

    function previous(step) {
        switch (step) {
            case 1:

                break;
            case 2:
                $('#dingXiangSheZhi').removeClass('cur-step');
                $('#one').addClass('show').removeClass('hide');
                $('#two').removeClass('show').addClass('hide');
                $('#shangYiBu').removeClass('show').addClass('hide');
                $('#quXiao1').removeClass('hide');
                break;
            case 3:
                $('#shangChuanSuCai').removeClass('cur-step');
                $('#three').addClass('hide').removeClass('show');
                $('#two').removeClass('hide').addClass('show');
                $('#one').addClass('hide').removeClass('show');
                 
                break;
            case 4:
                
                $('#tiJiaoXinXi').removeClass('cur-step');
                $('#four').addClass('hide').removeClass('show');
                $('#three').removeClass('hide').addClass('show');
                $('#xiaYiBu').text('下一步');
                break;
        }
    }

    function uploadBoxShow() {
        sessionStorage.setItem('guangGaoWeiLeiXing','banner');
        $('.creative-box').removeClass('hide');
    }

    function delCreative() {
        $('#suCaiList').html('');
    }


    function uploadBoxHide() {
        $('.creative-box').addClass('hide');
    }

    function showQua(){
        $('.star-box').toggleClass('open');
    }

    function chuangYiLeiXing(e){
        $('#showItem').text($(e).text());
        if($(e).text()=='视频'){

            $('#shangChuanFont').text('上传视频');
            $('#shangChuan_box').removeClass('hide');
        }else if($(e).text()=='原生'||$(e).text()=='单图'){

            $('#shangChuanFont').text('上传图片');

            $('#shangChuan_box').removeClass('hide');


        }else{
            $('#shangChuan_box').addClass('hide');
        }
    }

    //上传素材确认按钮
    function addCreative(){
        
        let chuangYiMingZi=$('#chuangYiMingZi').val();
        let chuangYiLeiXing=$('#showItem').text();
        let guangGaoWeiLeiXing=sessionStorage.getItem('guangGaoWeiLeiXing');
        let baoGuangJianCe=$('#baoGuangJianCe').val();
        // 图片路径暂未做

        if(!chuangYiMingZi){
            layer.msg('创意名字不能为空！');
            return false;
        }else if(!baoGuangJianCe){
            layer.msg('曝光监测不能为空！');
            return false;
        }

        // var fileObj = $("#file")[0].files; 
        // console.log(fileObj[0])
        // var formData=new FormData();
        // formData.append("key",fileObj[0]); 
        // formData.append("id",id); 
        // formData.append("token",token); 
        // $.ajax({
        //     type:"post",
        //     url:url+"/mineral/buyeth.html",
        //     async:true,
        //     data:formData,
        //     processData: false,
        //     contentType: false,
        //     dataType:'json',
        //     success:function(result){
        //         $(".deorlink").prop("disabled",false);
        //         if(result.status==1){
        //             alert(result.message);
        //         }else if(result.status==2){
        //             location.href="gxa://logout";
        //         }else{
        //             isErr(result)
        //         }
        //     }
        // });
        $('#suCaiList').html('');
        var html =`
                    <tr ng-repeat="mItem in materialList track by $index" class="ng-scope">
                        <td class="ng-binding marleft">1</td>
                        <td class="td-creative-content ng-binding">
                            创意名称：${chuangYiMingZi}<br><br>
                            广告位类型：${guangGaoWeiLeiXing}<br><br>
                            交互方式：仅展示<br><br>
                        </td>
                        <td>
                            <div ng-repeat="i in mItem.material" class="ng-scope">
                                <div ng-if="i.data" class="ng-scope">
                                    <span class="ng-binding">创意类型：</span>
                                    <span class="ng-binding">${chuangYiLeiXing}</span><br><br>
                                </div>
                            </div>
                            
                            <div ng-repeat="i in mItem.material" class="ng-scope">
                                <div ng-if="i.image" class="ng-scope">
                                    <span>图片：</span>
                                    <a href="javascript:;" onclick="showImg()">查看图片</a><br><br>
                                </div>
                            </div>

                            <div class="ng-binding">
                                曝光监测：${baoGuangJianCe}<br><br>

                            </div>
                        </td>
                        <td>
                            <span class="audit audit-orange">内审状态<span class="audit-text ng-binding">待审核</span></span>
                            <span class="audit audit-blue">待审核的平台<span class="audit-text ng-binding">0</span></span>
                            <span class="audit audit-green">通过审核的平台<span class="audit-text ng-binding">0</span></span>
                            <span class="audit audit-red">审核拒绝的平台<span class="audit-text ng-binding">0</span></span>
                        </td>
                        <td>
                            <button ng-disabled="mItem.auditState=='2'" class="dsp-btn btn-blue" ng-class="{'btn-not': mItem.auditState=='2'}" ng-click="creativeEdit(mItem, $index)" onclick="uploadBoxShow();">编辑</button>
                            <button class="dsp-btn btn-red" onclick="delCreative()">停用</button>
                        </td>
                    </tr>`;     
        $('#suCaiList').append(html);  
        $('.creative-box').addClass('hide');
    }
    
    function upload(){

    }

    function filechange(event){

        console.log(event);

        $("#file").val();

        var files = event.target.files;
        if (files && files.length > 0) {
            // 获取目前上传的文件
            file = files[0];// 文件大小校验的动作
            if(file.size > 1024 * 1024 * 2) {
                alert('图片大小不能超过 2MB!');
                return false;
            }
            
            $('#show_box').removeClass('hide');
            // 获取 window 的 URL 工具
            var URL = window.URL || window.webkitURL;
            // 通过 file 生成目标 url
            var imgURL = URL.createObjectURL(file);
            //用attr将img的src属性改成获得的url
            $("#showImg").attr("src",imgURL);
            // 使用下面这句可以在内存中释放对此 url 的伺服，跑了之后那个 URL 就无效了
            // URL.revokeObjectURL(imgURL);
        }
        console.log(files);
    };

    function filechange1(event){

        console.log(event);

        $("#file1").val();

        var files = event.target.files;
        if (files && files.length > 0) {
            // 获取目前上传的文件
            file = files[0];// 文件大小校验的动作
            if(file.size > 1024 * 1024 * 2) {
                alert('图片大小不能超过 2MB!');
                return false;
            }
            
            $('#show_box1').removeClass('hide');
            // 获取 window 的 URL 工具
            var URL = window.URL || window.webkitURL;
            // 通过 file 生成目标 url
            var imgURL = URL.createObjectURL(file);
            //用attr将img的src属性改成获得的url
            $("#showImg1").attr("src",imgURL);
            // 使用下面这句可以在内存中释放对此 url 的伺服，跑了之后那个 URL 就无效了
            // URL.revokeObjectURL(imgURL);
        }
    };

        //上传图片(这个项目没用到这个函数)
        function toPay(){
            var fileObj = $("#file")[0].files; 
            console.log(fileObj[0])
            var formData=new FormData();
            formData.append("key",fileObj[0]); 
            // formData.append("id",id); 
            // formData.append("token",token); 
            $.ajax({
                type:"post",
                url:url+"/mineral/buyeth.html",
                async:true,
                data:formData,
                processData: false,
                contentType: false,
                dataType:'json',
                success:function(result){
                    $(".deorlink").prop("disabled",false);
                    if(result.status==1){
                        alert(result.message);
                    }else if(result.status==2){
                        location.href="gxa://logout";
                    }else{
                        isErr(result)
                    }
                }
            });
        }

        function delPic(){
            $("#show_box").addClass('hide');
        }

        function delPic1(){
            $("#show_box1").addClass('hide');
        }

                //查看图片
        function imgShow(){
            let  url=$("#showImg").attr("src");
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: '516px',
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content: '<img style="height: 50%; width: 50%;" src="'+ url +'"></img>'
            });
        };

        //查看图片
        function imgShow1(){
            let  url=$("#showImg1").attr("src");
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: '516px',
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content: '<img style="height: 50%; width: 50%;" src="'+ url +'"></img>'
            });
        };

        function selectTianShi(e){
            $('#tian').text($(e).children('a').text()); 
        }

        function selectTianShi1(e){
            $('#tian1').text($(e).children('a').text()); 
        }

        function clickFuncHuo(e){

            $('#huoDongContent').text($(e).children('a').text());
            let huoDongId=$(e).children('a').attr('data-id');
            sessionStorage.setItem("huoDongId",huoDongId);
        }

        function clickFuncJian(e){

            $('#jianCeContent').text($(e).children('a').text()); 

            let jianCeId=$(e).children('a').attr('data-id');
            sessionStorage.setItem("jianCeId",jianCeId);
        }


        function selectTianShi2(e){
            $('#tian2').text($(e).children('a').text()); 
        }

        function selectTianShi3(e){
            $('#tian3').text($(e).children('a').text()); 
        }

        function showImg(){
            let src=$('#showImg').attr('src');
            
            layer.photos({
                photos: {
                    "data": [
                      {
                        "src": src,
                      }
                    ]
                  }
                ,anim: 5
              });
        }


    // 新建订单
    function addAdorder(){
        
        let token=sessionStorage.getItem("token");
        var adOrderDir = {};

       
        adOrderDir.ageNumber=sessionStorage.getItem('nianLingDingXiang');               //年龄范围
        adOrderDir.equipmentBrandDetails=sessionStorage.getItem('sheBeiPinPai');        //设备品牌

        adOrderDir.equipmentMoneyDetails=sessionStorage.getItem('sheBeiJiaGe');         //设备价格

        adOrderDir.equipmentVersionsDetails=sessionStorage.getItem('sheBeiBanBen');     //设备版本


        adOrderDir.incomeNumber=sessionStorage.getItem('shouRuDingXiang');              //收入金额

        adOrderDir.networkWay=sessionStorage.getItem('lianWangFangShi');                //联网方式

        adOrderDir.operatorDetails=sessionStorage.getItem('yunYingShang');              //运营商


        
        let sex=sessionStorage.getItem('xingBieDingXiang');                //性别定向
        if(sex=='不限'){
            adOrderDir.peopleSex=0;
        }else if(sex=='男'){
            adOrderDir.peopleSex=1;
        }else if(sex=='女'){
            adOrderDir.peopleSex=2;
        }
        


        var adOrderInfo = {};
        let dingDanData=JSON.parse(localStorage.getItem("dingDanData"));
        console.log(dingDanData);

        adOrderInfo.activityId= sessionStorage.getItem("huoDongId");            //选择的活动ID
        adOrderInfo.monitorId=sessionStorage.getItem("jianCeId");               //选择监测ID

        adOrderInfo.allBudget=dingDanData.yuSuanKongZhi;                                                 //总预算控制
        adOrderInfo.bidType=1;

        adOrderInfo.launchDateStart=$('#startTime').val();                              //投放开始时间
        adOrderInfo.launchDateEnd=$('#endTime').val();                                  //投放结束时间
        


        
        adOrderInfo.launchUnit=$('#tian2').children('span').text();        //投放次数单位

        let touFangSuLv1=localStorage.getItem('touFangSuLv');
        if(touFangSuLv1=='按花费控制'){
            adOrderInfo.launchType=1;                               //投放速率类型
            let touFangSuLv=$('#tian').children('span').text();
            if(touFangSuLv=='加速'){
                adOrderInfo.launchSpeed=1;                                 //投放速率
            }else if(touFangSuLv=='匀速'){
                adOrderInfo.launchSpeed=2;                                //投放速率
            }         
            
            adOrderInfo.launchTimes=$('#yuan').val();                         //投放次数
            adOrderInfo.launchUnit=$('#tian1').children('span').text();        //投放次数单位
        }else if(touFangSuLv1=='按展示量控制'){
            adOrderInfo.launchType=2;
            adOrderInfo.launchTimes=$('#qianCi').val();                         //投放次数
            adOrderInfo.launchUnit=$('#tian3').children('span').text();        //投放次数单位
        }

        //接口还没接  adOrderInfo.monitorId  监测管理ID

        adOrderInfo.orderMoney=$('#dingDanChuJia').val().trim();            //订单出价

        adOrderInfo.orderName=dingDanData.dingDanMingCheng;                     //订单名称

        adOrderInfo.profitNumber= $('#liRunZhi').val();                                       //利润值
        adOrderInfo.times=$('#ci').val();                                   //频次
        adOrderInfo.tunit=$('#tian2').children('span').text();               //频次天/小时

        var adOrderOri = [];
        var obj={};
      
    
        obj.exposureMonitor=$('#baoGuangJianCe').val();              //曝光监测

        let guangGaoWeiLeiXing=sessionStorage.getItem('guangGaoWeiLeiXing');
        if(guangGaoWeiLeiXing=='Banner'){
            obj.originalityAdType =2 ;                                                            //创意广告位类型
        }else if(guangGaoWeiLeiXing=='原生'){
            obj.originalityAdType =3 ; 
        }else if(guangGaoWeiLeiXing=='开屏'){
            obj.originalityAdType =0 ; 
        }
        else if(guangGaoWeiLeiXing=='插屏'){
            obj.originalityAdType =1 ; 
        }
        obj.originalityName=$('#chuangYiMingZi').val();                  //创意名字
        
        let chuangYiLeiXing=$('showItem').text();
        if(chuangYiLeiXing=='单图'){
            obj.originalityType =3 ;                                                            //创意类型
        }else if(chuangYiLeiXing=='原生'){
            obj.originalityType =4 ; 
        }else if(chuangYiLeiXing=='视频'){
            obj.originalityType =0 ; 
        }
        else if(chuangYiLeiXing=='H5'){
            obj.originalityType =1 ; 
        }

        // 上传图片获取图片路径
        

        var fileObj = $("#file")[0].files; 
        console.log(fileObj[0])
        var formData=new FormData();
        formData.append("file",fileObj[0]); 
        // formData.append("id",id); 
        // formData.append("token",token); 
       
        $.ajax({
            type:"POST",
            url:url+"/common/upload",  
            async:true,
            data:formData,
            processData: false,
            contentType: false,
            dataType:'json',
            success:function(result){
                console.log(result);
                if(result.code==0){
                    let imgUrl=result.data[0].url;
                    console.log(imgUrl);
                    obj.photoUrl=imgUrl;
                    adOrderOri.push(obj);
 

                    $.ajax({
                        url: url + "/advertiser/adOrderInfo/addAdorder",
                        type: 'POST',
                        //		参数需转为字符串
                        // data: JSON.stringify(d),


                        data :JSON.stringify({
                        //下面的左方的scatalog和scontent名字必须和TestSendValueDto 类的这两个类的属性名保持一致!!!!复制过来的参考用
                            adOrderDir,
                            adOrderInfo,
                            adOrderOri
                        }),
                        //		json跨域
                        dataType: 'json',
                        //		contentType类型为json
                        contentType: "application/json",

                        //		请求头加上X-Token 
                        beforeSend: function(XMLHttpRequest) {
                            //		token 为页面所获取
                            
                            XMLHttpRequest.setRequestHeader("X-Token", token); 
                        },
                        useDefaultXhrHeader: false,
                        success: function(result) {
                            console.log(result);
                            if(result.code=='0'){
                                layer.open({title: '提示', icon: '1', content:result.msg,time:1500,end:function(){
                                     location.href='order.html';
                                }});
                                
                            }


                            // if(result.code == '0') {
                            //     getListData(result.data.rows);
                            //     if(result.data.total>0){
                            //         if(result.data.total%pageSize==0){
                            //             allPageNum=result.data.total/pageSize;
                            //         }else{
                            //             allPageNum=parseInt(result.data.total/pageSize)  + 1
                            //         }

                            //         $('#fenYe').children('.a').remove();
                            //         let html = '';
                            //         for(let i=0;i<allPageNum;i++){
                            //             if(i!=page-1){
                            //                 html +=` <li data-page="${i+1}" class="ui-pager a" onclick="qieHuan(this)" >${i+1}</li>`;
                            //             }else{
                            //                 html +=` <li data-page="${i+1}" class="ui-pager focus a" onclick="qieHuan(this)">${i+1}</li>`;
                            //             }
                            //         }
                            //         $('#fenYe').append(html); 
                            //     }
                            // } else {
                            //     isErr(result);
                            // }


                        },
                        err: function(err) {
                            layer.msg("请求失败");
                        },
                        complete: function() {
                            // $(_that).removeAttr("disabled");
                        }
                    });


                }
            
            }

            
        });
                                                 
        
    }

    //正则效验是否是数字
    function checkRate(input) {
    　　var re = /^[0-9]+.?[0-9]*$/; //判断字符串是否为数字 //判断正整数 /^[1-9]+[0-9]*]*$/ 
    　　var nubmer = document.getElementById(input).value;

    　　if (!re.test(nubmer)) {
    　　　　alert("请输入数字");
    　　　　document.getElementById(input).value = "";
    　　　　return false;
    　　}
    }